/* eslint-disable @typescript-eslint/no-var-requires */
// const { defineConfig } = require('@vue/cli-service');
const NodePolyfillPlugin = require('node-polyfill-webpack-plugin');
const ForkTsCheckerWebpackPlugin = require('fork-ts-checker-webpack-plugin');
const AutoImport = require('unplugin-auto-import/webpack');
const Components = require('unplugin-vue-components/webpack');
const { ElementPlusResolver } = require('unplugin-vue-components/resolvers');
const fs = require('fs');
const path = require('path');
module.exports = {
  transpileDependencies: true,
  lintOnSave: false,
  devServer: {
    client: {
      overlay: false
    },
    open: true,
    host: '0.0.0.0', // 允许外部ip访问
    port: 8085, // 端口
    https: {
      key: fs.readFileSync('./server.key'),
      cert: fs.readFileSync('./server.crt'),
    },
    proxy: {
      '/api': {
        target: 'https://192.168.1.162:8082', // 后端API的地址
        changeOrigin: true, // 是否改变源地址
        ws: true,
        pathRewrite: { '^/api': '' } // 重写路径
      }
    }

  },
  css: {
    loaderOptions: {
      scss: {
        additionalData: `@use "@/assets/skin/orange/index.scss" as *;`,
      },
    },
  },
  configureWebpack: {
    resolve: {
      alias: {
        // 将该链接映射为一个别名，方便在项目中引用
        '@ali/cc - workbench - sdk': 'https://g.alicdn.com/cloudcallcenter/web-workbench-sdk/3.3.5/ui.min.js'
      }
    }
  },
  configureWebpack: config => {
    // remove the existing ForkTsCheckerWebpackPlugin
    // config.plugins = config.plugins.filter(p => !(p instanceof ForkTsCheckerWebpackPlugin));

    config.plugins.push(
      new NodePolyfillPlugin({
        // typescript: {
        //   configFile: path.resolve(__dirname, 'tsconfig.json'),
        // }
      }),
    );
    config.plugins.push(
      AutoImport({
        imports: ['vue', 'vue-router', 'pinia'],
        resolvers: [ElementPlusResolver()],
      }),
    );
    config.plugins.push(
      Components({
        resolvers: [ElementPlusResolver({ importStyle: 'sass' })],
        directoryAsNamespace: true,
      }),
    );

  },
};
